export const createScript = () => {
  const windowWidth = document.getElementById("app");
  if (this.appendScript || windowWidth.offsetWidth <= 900) return;
  let script = document.createElement("script");
  script.setAttribute("color", "0,0,0");
  script.setAttribute("opacity", "1");
  script.setAttribute("count", "99");
  script.setAttribute("zIndex", "1");
  script.type = "text/javascript";
  script.src = "https://cdn.bootcss.com/canvas-nest.js/1.0.1/canvas-nest.js";
  document.getElementsByTagName("body")[0].appendChild(script);
  this.appendScript = true;
  this.$nextTick(() => {
    setTimeout(() => {
      let c = document.getElementsByTagName("canvas");
      if (!c || c.length === 0) {
        this.appendScript = false;
        return;
      }
      c[c.length - 1].style.pointerEvents = "none";
      c[c.length - 1].style.opacity = "1";
      c[c.length - 1].style.zIndex = "1";
    }, 100);
  });
};
export const removeLogin = () => {
  localStorage.removeItem("JBlogLogin");
  localStorage.removeItem("JUsername");
  localStorage.removeItem("JPassword");
};
export const setBgImg = () => {
  let imgSrc =
    "url('https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F1114%2F0R620115Q8%2F200R6115Q8-6-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1659597064&t=2a528829a0144e17f0fdc21db6cb9842') no-repeat";
  const bgDom = document.createElement("div");
  const app = document.getElementById("app");
  if (app.offsetWidth <= 900) {
    imgSrc =
      "url('https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F201702%2F15%2F20170215210231_XMrKH.thumb.400_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1659597162&t=13b0d5eda071a359d9f51a071fa2cae8') no-repeat";
  }
  bgDom.style.position = "fixed";
  bgDom.style.top = 0;
  bgDom.style.background = imgSrc;
  bgDom.style.width = "100vw";
  bgDom.style.height = "100vh";
  bgDom.style.backgroundSize = "cover";
  bgDom.style.backgroundPosition = "center";
  const body = document.getElementsByTagName("body")[0];
  body.insertBefore(bgDom, app);
};
